<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Section 1.10.&nbsp; Time Values</title>
<link rel="STYLESHEET" type="text/css" href="images/style.css">
<link rel="STYLESHEET" type="text/css" href="images/docsafari.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch01lev1sec9.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch01lev1sec11.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
<br><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><a name="ch01lev1sec10"></a>
<h3 class="docSection1Title" id="454331-897">1.10. Time Values</h3>
<p class="docText"><a name="idd1e4377"></a><a name="idd1e4380"></a><a name="idd1e4383"></a><a name="idd1e4388"></a><a name="idd1e4393"></a><a name="idd1e4396"></a><a name="idd1e4401"></a><a name="idd1e4406"></a><a name="idd1e4411"></a><a name="idd1e4416"></a><a name="idd1e4419"></a><a name="idd1e4424"></a><a name="idd1e4429"></a><a name="idd1e4434"></a><a name="idd1e4439"></a><a name="idd1e4444"></a><a name="idd1e4447"></a>Historically, UNIX systems have maintained two different time values:</P>
<div style="font-weight:bold"><ol class="docList" type="1"><LI><div style="font-weight:normal"><p class="docList">Calendar time. This value counts the number of seconds since the Epoch: 00:00:00 January 1, 1970, Coordinated Universal Time (UTC). (Older manuals refer to UTC as Greenwich Mean Time.) These time values are used to record the time when a file was last modified, for example.</p><p class="docList">The primitive system data type <tt>time_t</tt> holds these time values.</P></div></LI><LI><div style="font-weight:normal"><p class="docList">Process time. This is also called CPU time and measures the central processor resources used by a process. Process time is measured in clock ticks, which have historically been 50, 60, or 100 ticks per second.</p><p class="docList">The primitive system data type <tt>clock_t</tt> holds these time values. (We'll show how to obtain the number of clock ticks per second with the <tt>sysconf</tt> function in <a class="docLink" href="ch02lev1sec5.html#ch02lev2sec15">Section 2.5.4</a>.)</P></div></LI></ol></div>
<p class="docText">When we measure the execution time of a process, as in <a class="docLink" href="ch03lev1sec9.html#ch03lev1sec9">Section 3.9</a>, we'll see that the UNIX System maintains three values for a process:</P>
<ul><LI><p class="docList">Clock time</p></LI><LI><p class="docList">User CPU time</P></li><LI><p class="docList">System CPU time</P></li></UL>
<p class="docText">The clock time, sometimes called <span class="docEmphasis">wall clock time</span>, is the amount of time the process takes to run, and its value depends on the number of other processes being run on the system. Whenever we report the clock time, the measurements are made with no other activities on the system.</P>
<p class="docText">The user CPU time is the CPU time attributed to user instructions. The system CPU time is the CPU time attributed to the kernel when it executes on behalf of the process. For example, whenever a process executes a system service, such as <tt>read</tt> or <tt>write</tt>, the time spent within the kernel performing that system service is charged to the process. The sum of user CPU time and system CPU time is often called the <span class="docEmphasis">CPU time</span>.</p>
<p class="docText">It is easy to measure the clock time, user time, and system time of any process: simply execute the <tt>time</tt>(1) command, with the argument to the <tt>time</tt> command being the command we want to measure. For example:</p>

<pre>
   $ <span class="docEmphStrong">cd /usr/include</span>
   $ <span class="docEmphStrong">time -p grep _POSIX_SOURCE */*.h &gt; /dev/null</span>

   real    0m0.81s
   user    0m0.11s
   sys     0m0.07s
</pre><br>

<p class="docText">The output format from the <tt>time</tt> command depends on the shell being used, because some shells don't run <tt>/usr/bin/time</tt>, but instead have a separate built-in function to measure the time it takes commands to run.</p>
<p class="docText">In <a class="docLink" href="ch08lev1sec16.html#ch08lev1sec16">Section 8.16</a>, we'll see how to obtain these three times from a running process. The general topic of times and dates is covered in <a class="docLink" href="ch06lev1sec10.html#ch06lev1sec10">Section 6.10</a>.</P>

<ul></UL></td></TR></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch01lev1sec9.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch01lev1sec11.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
</body></html><br>
<table width="100%" cellspacing="0" cellpadding="0"
style="margin-top: 0pt; border-collapse: collapse;"> 
<tr> <td align="right" style="background-color=white; border-top: 1px solid gray;"> 
<a href="http://www.zipghost.com/" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">The CHM file was converted to HTM by Trial version of <b>ChmD<!--31-->ecompiler</b>.</a>
</TD>
</TR><tr>
<td align="right" style="background-color=white; "> 
<a href="http://www.etextwizard.com/download/cd/cdsetup.exe" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">Download <b>ChmDec<!--31-->ompiler</b> at: http://www.zipghost.com</a>
</TD></tr></table>
